<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>专业列表</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
		<script src="../../static/js/jquery-1.11.1.min.js"></script>
		<script src="../../static/js/common.js" charset="utf-8"></script>

	</head>

	<body>
		<div class="weadmin-nav">
			<span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">专业管理</a>
        <a><cite>专业列表</cite></a>
      </span>
			<a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon" style="line-height:30px">刷新</i></a>
		</div>
		<div class="weadmin-body">
			<div class="layui-row" id="search">
				<form class="layui-form layui-col-md12 we-search">
					<div class="layui-inline">
						<input class="layui-input" placeholder="开始日" name="start" id="start">
					</div>
					<div class="layui-inline">
						<input class="layui-input" placeholder="截止日" name="end" id="end">
					</div>
					<div class="layui-inline">
						<input type="text" name="username" placeholder="请输入专业名称" autocomplete="off" class="layui-input">
					</div>
					<button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
				</form>
			</div>
			<div class="weadmin-block">
				<button class="layui-btn" onclick="WeAdminShow('添加专业','./add.html')"><i class="layui-icon"></i>添加</button>
			</div>
			<table class="layui-hide" id="gradeclassList" lay-filter="gradeclassbar"></table>
			<script type="text/html" id="gradeclassOpBar">
				<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
			</script>
			<div id="editForm" style="display: none">
				<form class="layui-form">
					<div class="layui-form-item">
						<label for="gradeclassname" class="layui-form-label">
							<span class="we-red">*</span>专业名称
						</label>
						<div class="layui-input-inline">
							<input type="text" id="gradeclassname" name="gradeclassname" required="" lay-verify="required" autocomplete="off" class="layui-input">
						</div>
					</div>

					<div class="layui-form-item" pane>
						<label  class="layui-form-label">
							<span for="L_department" class="we-red">*</span>隶属学院
						</label>
						<div class="layui-input-inline">
							<select id="L_department" name="department" lay-verify="required" lay-filter="department" >

							</select>
						</div>
					</div>
					<div class="layui-form-item layui-form-text">
						<label for="gradeclassdesc" class="layui-form-label">职能描述</label>
						<div class="layui-input-block">
							<textarea placeholder="请输入内容" id="gradeclassdesc" name="gradeclassdesc" class="layui-textarea" lay-verify="detail|required"></textarea>
						</div>
					</div>
				</form>
			</div>

		</div>
		<script>
            layui.extend({
                admin: '{/}../../static/js/admin'
            });

            layui.use(['table', 'jquery','form', 'admin'], function() {
                var table = layui.table,
                    $ = layui.jquery,
                    form = layui.form,
                    admin = layui.admin;
                $.ajax({
                    url: remoteUrl+"grade_class",
                    type: "GET",
                    contentType: "application/json;charset=utf-8",
                    success: function (json) {
                        if (json.result == "") {
                            json.result = {};
                        } else {
                            table.render({
                                elem: '#gradeclassList',
                                cellMinWidth: 80,
                                cols: [
                                    [ {
                                        field: 'id',title: '专业编码',sort:true
                                    },{
                                        field: 'name',title: '专业名称',sort:true
                                    },{
                                        field: 'departmentname',title: '隶属学院',templet:function(res){
                               			 	return '<em>' + res.department.name + '</em>'
                           			 	}
                                    } ,{
                                        field: 'detail',title: '职能描述'
                                    },{
                                        field: 'operate',title: '操作',align:'center',toolbar: '#gradeclassOpBar',unresize: true
                                    }]
                                ],
                                data: json.result,
                                event: true,
                                page: true
                            });

                            //监听工具条
                            table.on('tool(gradeclassbar)', function(obj){
                                var data = obj.data;
                                if(obj.event === 'detail'){

                                    layer.msg('ID：'+ data.id + ' 的查看操作');

                                } else if(obj.event === 'del'){
                                    layer.confirm('真的删除行么', function(index){
                                        $.ajax({
                                            url: remoteUrl+"grade_class/"+data.id,
                                            type: "DELETE",
                                            contentType: "application/json;charset=utf-8",
                                            success: function (json) {
                                                obj.del();
                                                layer.close(index);
                                                layer.alert("删除成功")
                                            }
                                        });



                                    });
                                } else if(obj.event === 'edit'){
                                    layer.open({
                                        type: 1,
                                        fix: false, //不固定
                                        maxmin: true,
                                        shadeClose: true,
                                        area: [600 + 'px', 500 + 'px'],
                                        shade: 0.4,
                                        title: "编辑",
                                        content: $('#editForm'),
                                        success: function () {
                                            //加载部门信息
                                            $.ajax({
                                                url: remoteUrl+"department",
                                                type: 'get',//method请求方式，get或者post
                                                dataType: 'json',//预期服务器返回的数据类型
                                                contentType: "application/json; charset=utf-8",
                                                async: false,
                                                success: function (res) {//res为相应体,function为回调函数
                                                    var result = res.result;
                                                    var i = 0;
                                                    var op = "";
                                                    $('#L_department').append('<option value="">请选择</option>');
                                                    for (i; i < result.length; i++) {
                                                        op += '<option value=' + result[i].id + '>' + result[i].name + '</option>';
                                                    }
                                                    $('#L_department').append(op);
                                                    $('#L_department').find('option[value=' + data.department.id + ']').attr("selected", true);
                                                    form.render();
                                                }
                                            });
                                            $("#gradeclassname").val(data.name);
                                            $("#gradeclassdesc").val(data.detail);
                                        }})
                                }
                            });
                        }
                    }
                });
				/*
				 *数据表格中form表单元素是动态插入,所以需要更新渲染下
				 * http://www.layui.com/doc/modules/form.html#render
				 * */
                $(function(){
                    form.render();
                });
            });
		</script>
	</body>

</html>